const mongoose = require('mongoose');

const { dbUrl } = require('../config/config.default')
mongoose.connect( dbUrl, { useNewUrlParser: true, useUnifiedTopology: true });

const db = mongoose.connection

// 当连接失败的时候
db.on('error', console.error.bind(console, 'MongoDB 数据连接失败 error:'))

// 连接成功的时候
db.once('open', function() {
  console.log('MongoDB 数据连接成功');
})

module.exports = {
  User: mongoose.model('User', require('./user')),
  Article: mongoose.model('Article', require('./article')),
}